﻿<Page x:Class="SqlCeViewer.New3DWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:_3DTools;assembly=3DTools"
    xmlns:MyControl="clr-namespace:MPL.MyControls;assembly=MPL"
    xmlns:CommonControl="clr-namespace:SqlCeViewer.CommonUI"
    Title="SqlCeViewer 3D Entry" >
    <Page.Resources>
        <!-- Visuals -->
        <Border BorderBrush="LightBlue" BorderThickness="1" Background="Transparent" x:Key="Visual1">
            <StackPanel Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <MyControl:ScrollableListBox Height="180" 
                     ScrollViewer.IsDeferredScrollingEnabled="False"
                     ScrollViewer.HorizontalScrollBarVisibility="Visible"
                     ScrollViewer.VerticalScrollBarVisibility="Hidden"
                ItemsSource="{Binding}" x:Name="DbCollectionList" Margin="5,0,5,0" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border Width="120" Height="Auto"
                            Tag="{Binding Path=NewURL}"
                            MouseLeftButtonDown="Border_MouseLeftButtonDown"
                                    MouseEnter="Border_MouseEnter"
                                    MouseLeave="Border_MouseLeave"
                        Margin="15">
                            <StackPanel>
                                <Image Source="{Binding Path=LogoImage}" 
                                       Tag="{Binding Path=NewURL}" Height="100">
                                    <Image.ToolTip>
                                        <StackPanel Opacity="0.8">
                                            <TextBlock Text="{Binding Path=ToolTipText}" Foreground="Blue" FontSize="15"/>
                                        </StackPanel>
                                    </Image.ToolTip>
                                </Image>
                                <TextBlock Text="{Binding Path=Comment}" HorizontalAlignment="Center"></TextBlock>
                            </StackPanel>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal"></VirtualizingStackPanel>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </MyControl:ScrollableListBox>
            <MyControl:ScrollableListBox x:Name="themeListBox" ItemsSource="{Binding}" Margin="10,0,10,0"
                         ScrollViewer.IsDeferredScrollingEnabled="False"
                         ScrollViewer.HorizontalScrollBarVisibility="Visible"
                     ScrollViewer.VerticalScrollBarVisibility="Visible">
                <ListBox.ToolTip>
                    <StackPanel>
                        <StackPanel Width="400">
                            <Label FontWeight="Bold" Background="LightCyan" Foreground="Red">Tips</Label>
                            <TextBlock Margin="4,4,0,0" Text="You can right click to restore to default theme" FontSize="12"></TextBlock>
                            <Line Stroke="Black" StrokeThickness="1" Width="400">
                            </Line>
                            <StackPanel Orientation="Horizontal">
                                <Label FontWeight="Bold">
                                    Home Page : https://sourceforge.net/projects/sqlceviewer
                                </Label>
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </ListBox.ToolTip>
                <ListBox.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Restore theme" Click="MenuItem_Click"/>
                    </ContextMenu>
                </ListBox.ContextMenu>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border Width="20" Height="Auto"
                                    MouseEnter="Border_MouseEnter_Theme"
                                    MouseLeave="Border_MouseLeave_Theme"
                        Margin="15">
                            <StackPanel>
                                <Image Source="{Binding Path=ThemeIcon}"
                                           Tag="{Binding}" 
                                           PreviewMouseLeftButtonDown="Image_PreviewMouseLeftButtonDown"
                                           Height="20">
                                    <Image.ToolTip>
                                        <StackPanel>
                                            <TextBlock Text="{Binding ThemeName}" FontSize="15" Foreground="Blue"></TextBlock>
                                        </StackPanel>
                                    </Image.ToolTip>
                                </Image>
                            </StackPanel>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal"></VirtualizingStackPanel>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </MyControl:ScrollableListBox>
            </StackPanel>
        </Border>

        <Border x:Key="Visual2" BorderBrush="LightBlue" BorderThickness="1" Background="Transparent">
            <StackPanel Margin="0,0,0,0" Grid.Column="1" Width="Auto" 
                        Height="Auto"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <CommonControl:AppendixPanel x:Name="appendixPanel"/>
            </StackPanel>
        </Border>

        <!-- 3D Transforms-->
        <Transform3DGroup x:Key="Transform1">
            <RotateTransform3D>
                <RotateTransform3D.Rotation>
                    <AxisAngleRotation3D Angle="15" Axis="0 1 0" />
                </RotateTransform3D.Rotation>
            </RotateTransform3D>
            <TranslateTransform3D OffsetX="-1"/>
        </Transform3DGroup>

        <Transform3DGroup x:Key="Transform2">
            <RotateTransform3D>
                <RotateTransform3D.Rotation>
                    <AxisAngleRotation3D Angle="-15" Axis="0 1 0" />
                </RotateTransform3D.Rotation>
            </RotateTransform3D>
            <TranslateTransform3D OffsetX="1.0"/>
        </Transform3DGroup>

        <!-- 3D Models -->
        <MeshGeometry3D x:Key="PlaneMesh" Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0" TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3"/>

        <!-- Materials -->
        <DiffuseMaterial x:Key="Material1">
            <DiffuseMaterial.Brush>
                <VisualBrush Visual="{StaticResource Visual1}"/>
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>

        <DiffuseMaterial x:Key="Material2">
            <DiffuseMaterial.Brush>
                <VisualBrush Visual="{StaticResource Visual2}"/>
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
    </Page.Resources>
    <Grid>
        <DockPanel>
            <Path StrokeThickness="1.500000" Stroke="#ffffffff" StrokeMiterLimit="1.000000" DockPanel.Dock="Bottom"
              Fill="Blue" PreviewMouseLeftButtonDown="CallTraditioalWind_PreviewMouseLeftButtonDown"
              Data="F1 M 9.816406,1.694336 L 12.351074,6.830078 L 18.018066,7.654297 L 13.918457,11.654297 L 14.886230,17.299805 L 9.816406,14.630859 L 4.746094,17.299805 L 5.713867,11.654297 L 1.611328,7.654297 L 7.281250,6.830078 L 9.816406,1.694336 Z" 
              HorizontalAlignment="Left" VerticalAlignment="Center" x:Name="CallTraditioalWind" ToolTip="Press here to change to traditional view"/>
        <local:TrackballDecorator>
            <local:Interactive3DDecorator>
                <Viewport3D >
                    <Viewport3D.Camera>
                        <PerspectiveCamera Position="0, 0, 6"/>
                    </Viewport3D.Camera>
                    <local:InteractiveVisual3D Transform="{StaticResource Transform1}" 
                                     Geometry="{StaticResource PlaneMesh}"
                                     Visual="{StaticResource Visual1}" />
                    <local:InteractiveVisual3D Transform="{StaticResource Transform2}" 
                                     Geometry="{StaticResource PlaneMesh}"
                                     Visual="{StaticResource Visual2}" />
                    <ModelVisual3D>
                        <ModelVisual3D.Content>
                            <DirectionalLight Color="Transparent" Direction="0,0,-1"/>
                        </ModelVisual3D.Content>
                    </ModelVisual3D>
                </Viewport3D>
            </local:Interactive3DDecorator>
        </local:TrackballDecorator>
        
        </DockPanel>
    </Grid>
</Page>
